﻿namespace Sai.Core.Introspection
{
	using System;
    using System.Text;

    public class EventDeclaration : FunctionMember, IExactlyMatch<EventDeclaration>, ILooselyMatch<EventDeclaration>, ISourceCodeProvider 
	{
		public EventDeclaration(TypeName typeName)
			: base(typeName)
		{
		}

		public EventDeclaration(string name, TypeName typeName, ObsoleteMarker obsolete, TypeName declaringType)
			: base(typeName, obsolete, declaringType)
		{
			this.Name = name;
			//this.Parameters = new ParameterCollection();
		}

		public string Name { get; set; }

		//public ParameterCollection Parameters { get; private set; }

		public override string ToString()
		{
			return string.Format(
				"event {0} {1}",
				this.TypeName,
				this.Name);
		}

        public bool ExactMatchFor(EventDeclaration other)
        {
            // exact match is not needed for property - 
            // match on name and then dig deeper
            return this.LooseMatchFor(other);
        }

        public SourceCode ToCode()
        {
            SourceCode code = new SourceCode();

            code.Add(new KeywordTag("event"));
            code.Add(this.TypeName.ToCode());
            code.Add(new IdentifierTag(this.Name));

            return code;
        }

        public bool LooseMatchFor(EventDeclaration other)
        {
            // matches if the names are the same
            return string.Compare(
                this.Name,
                other.Name,
                StringComparison.Ordinal) == 0;
        }

	}
}
